layui.config({
	base : "js/"
}).use(['form','layer'],function(){
	var form = layui.form,
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		$ = layui.jquery;
	//video背景
	$(window).resize(function(){
		if($(".video-player").width() > $(window).width()){
			$(".video-player").css({"height":$(window).height(),"width":"auto","left":-($(".video-player").width()-$(window).width())/2});
		}else{
			$(".video-player").css({"width":$(window).width(),"height":"auto","left":-($(".video-player").width()-$(window).width())/2});
		}
	}).resize();
	//登录按钮事件
	form.on("submit(login)",function(data){
		sessionStorage.removeItem('projectselect');
        var load =  layer.load(2, {
            shade: [0.6,'#fff'] //0.1透明度的白色背景
		})
        $.ajax({
			url: PUATTRBUTE.REQUESTURL + '/api/user/login',
			data: {account: data.field.username, password: data.field.password},
            dataType:'json',
            type: 'post',
			success: function (res) {
				if(res.code == 1){
                    layer.msg(res.msg, {time: 1000, icon:1});
                    var userinfo = {
                        token: res.data.userinfo.token,
                        user_id: res.data.userinfo.user_id,
                        nickname: res.data.userinfo.nickname,
						pwd: data.field.password
					}
                    window.sessionStorage.setItem('userinfo', JSON.stringify(userinfo));
                    window.setTimeout(function(){
                        window.location.href = "../../index.html";
					}, 1000)
				}else{
                    layer.msg(res.msg, {time: 1000, icon:2});
				}
            },
            error:function(err){
				layer.msg('系统异常', {time: 1000, icon:5})
			},
            complete: function(){
                layer.close(load)
			}
        })
		return false;
	})
})
